package com.zrx.zrxaiagent.demo;

import cn.hutool.http.HttpRequest;

public class DashScopeApiClient {
    
    private static final String API_KEY = ""; // 或从配置文件读取
    
    public static void main(String[] args) {
        // 请求体JSON字符串
        String requestBody = """
                {
                    "model": "qwen-plus",
                    "messages": [
                        {
                            "role": "system",
                            "content": "You are a helpful assistant."
                        },
                        {
                            "role": "user",
                            "content": "你是谁？"// 方式1：使用构造器注入
                                                 @Service
                                                 public class ChatService {
                                                     private final ChatClient chatClient;
                                                    \s
                                                     public ChatService(ChatClient.Builder builder) {
                                                         this.chatClient = builder
                                                             .defaultSystem("你是恋爱顾问")
                                                             .build();
                                                     }
                                                 }
                                                 
                                                 // 方式2：使用建造者模式
                                                 ChatClient chatClient = ChatClient.builder(chatModel)
                                                     .defaultSystem("你是恋爱顾问")
                                                     .build();
                                                 
                        }
                    ]
                }
                """;
        
        // 发送请求
        String response = HttpRequest.post("https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions")
            .header("Authorization", "Bearer " + API_KEY)
            .header("Content-Type", "application/json")
            .body(requestBody)
            .timeout(30000) // 设置超时时间
            .execute()
            .body();
        
        // 输出响应
        System.out.println(response);
    }
}
